﻿using AutoUpdaterDotNET;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Threading.Tasks;

namespace UpdaterWeb
{
    class Program
    {
        static void Main(string[] args)
        {
            //1.杀死进程
            //杀死主程序进程
            Console.WriteLine("杀死进程");
            string appname = "Web打印插件";
            Process[] processes = Process.GetProcessesByName(appname);
            foreach (var p in processes)
                p.Kill();
            var sourcefile = AppDomain.CurrentDomain.BaseDirectory + appname + ".exe";
            var dfile = AppDomain.CurrentDomain.BaseDirectory + appname + DateTime.Now.Date.ToString("MMdd")+".exe";
            //重命名程序
            File.Copy(sourcefile, dfile);
            File.Delete(sourcefile);
            //2.下载程序
            try
            {
                //logger.Error(" 服务升级 ");
                Console.WriteLine("下载替换程序");
                AutoUpdater.Synchronous = true;
                AutoUpdater.RunUpdateAsAdmin = true;
                AutoUpdater.OpenDownloadPage = false;
                AutoUpdater.Mandatory = true;
                AutoUpdater.UpdateMode = Mode.ForcedDownload;//直接下载替换 
                
                AutoUpdater.Start("http://xinghecloud.cn:81/webUpdater.xml"); //用WinRAR加压不能到这里来
                //当前UpdaterWeb程序集版本和服务器版本比较

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                //logger.Error(ex.Message);
                throw;
            }
            //3.替换程序
            //4.启动程序
            //Process.Start(sourcefile);
        }
       
    }
}
